using System;
using System.Reflection;

namespace SAP.BusinessOne.Mackinac.Generator.Model
{
    public class ArgumentInfo
    {
        public ArgumentInfo(ParameterInfo pi)
        {
            if (pi.ParameterType.FullName == "System.Void")
            {
                Type = "void";
            }
            else
            {
                Type = GetTypeName(System.Type.GetTypeCode(pi.ParameterType));
                Name = pi.Name;
            }
        }

        private string GetTypeName(TypeCode code)
        {
            switch (code)
            {
                case TypeCode.Boolean:
                    return "bool";
                case TypeCode.Byte:
                    return "unsigned char";
                case TypeCode.Double:
                    return "double";
                case TypeCode.Empty:
                    return "void";
                case TypeCode.Int16:
                case TypeCode.Char:
                    return "short";
                case TypeCode.Int32:
                    return "int";
                case TypeCode.Int64:
                    return "long long";
                case TypeCode.SByte:
                    return "char";
                case TypeCode.Single:
                    return "float";
                case TypeCode.String:
                    return "const wstring&";
                case TypeCode.UInt16:
                    return "unsigned short";
                case TypeCode.UInt32:
                    return "unsigned int";
                case TypeCode.UInt64:
                    return "unsigned long long";
                case TypeCode.Object:
                case TypeCode.DBNull:
                case TypeCode.DateTime:
                case TypeCode.Decimal:
                default:
                    throw new NotSupportedException("The specific type is not supported; " + code.ToString());
            }
        }

        public string Type { get; set; }
        public string Name { get; set; }
        public override string ToString()
        {
            return Type + " " + Name;
        }
    }
}